package cn.zxh.csdn_maven.atomy.auth.letter;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;

import cn.zxh.csdn_maven.base.pojo.User;
import cn.zxh.csdn_maven.base.util.GetHtmlFromUrl;

/**
 * 发送私信
 * 
 * @author zxh
 * 
 */
@SuppressWarnings(value={"unused","deprecation"})
public class Letter {
	private Logger logger = Logger.getLogger(Letter.class);
	/** 模拟请求的工具类 */
	private HttpClient client = null;
	/** 用户信息 */
	private User user = null;
	/** 请求地址 */
	private String msgUrl = "http://msg.csdn.net/";
	public Letter() {
		client = new DefaultHttpClient();
	}
	
	public boolean start(String receiver , String content) throws Exception{
		logger.info(String.format("正在发送给%1$s....", receiver));
		Map<String, String> params = new HashMap<String, String>();
		String firstUrl = msgUrl+"letters/model?receiver="+receiver;
		params.put("base_url", firstUrl);
		/**设置cookie*/
		GetHtmlFromUrl.getInstance().getHtml(params);
		/**开始发送*/
		String sendUrl = msgUrl+"letters/send_message?receiver=%1$s&model_send_message=true&body=%2$s";
		sendUrl=String.format(sendUrl, receiver,content);
		params.put("base_url", sendUrl);
		params.put("Host", msgUrl);
		params.put("Referer", firstUrl);
		GetHtmlFromUrl.getInstance().getHtml(params);
		/**默认发送成功*/
		return true;
	}
}
